package general.socketmanager;

import java.net.ServerSocket;
import java.net.Socket;

public class cServerThread implements Runnable {
	
	private int iID;
	private ServerSocket oSocket;
	private iServerThreadListener oListener;
	
	public cServerThread(int iID, ServerSocket oSocket, iServerThreadListener oListener) {
		this.iID = iID;
		this.oSocket = oSocket;
		this.oListener = oListener;
	}
	
	public void SetListener(iServerThreadListener oListener) {
		this.oListener = oListener;
	}

	@Override
	public void run() {
		Socket oNewSocket;
		
		while (true) {
			try {
				// awaiting new connection
				oNewSocket = oSocket.accept();

				// return socket to manager
				oListener.OnNewConnection(iID, oNewSocket);
				
			}
			catch (Exception ex) {
				
			}
		}
	}

}
